import axios from "axios";
import { RootThunkAction } from '..';

// channel对象类型
export type Channel = {
  id: number
  name: string
}

export type ChannelAction = {
  type: 'channel/getChannelist',
  payload: Channel[]
}
  |
{
  type: "channel/changeActive"
  id: number
}

export function getChannelList(): RootThunkAction {
  return async dispatch => {
    const res = await axios.get('http://geek.itheima.net/v1_0/channels')
    dispatch({
      type: "channel/getChannelist",
      payload: res.data.data.channels
    })
    console.log(res)
  }
}

export function changeActive(id: number): ChannelAction {
  return {
    type: 'channel/changeActive',
    id
  }
}